//
//  WoShouListCell.m
//  ReceiptDelivery
//
//  Created by 吕晶 on 2020/10/9.
//  Copyright © 2020 吕晶. All rights reserved.
//

#import "WoShouListCell.h"

@interface WoShouListCell ()

@property (nonatomic, strong) UIView *bgView;
@property (nonatomic, strong) UILabel *noTitleLab;
@property (nonatomic, strong) UILabel *noLab;
@property (nonatomic, strong) UIButton *fuZhiBtn;
@property (nonatomic, strong) UILabel *fromAddLab;
@property (nonatomic, strong) UIImageView *statusImgView;
@property (nonatomic, strong) UILabel *statusLab;
@property (nonatomic, strong) UILabel *toAddLab;
@property (nonatomic, strong) UILabel *faHuoTitleLab;
@property (nonatomic, strong) UILabel *faHuoLab;
@property (nonatomic, strong) UILabel *companyTitleLab;
@property (nonatomic, strong) UILabel *companyLab;
@property (nonatomic, strong) UILabel *timeTitleLab;
@property (nonatomic, strong) UILabel *timeLab;

@end

@implementation WoShouListCell

+ (instancetype)WoShouListCellWithTableView:(UITableView *)tableView {
    static NSString *cellID = @"WoShouListCell";
    WoShouListCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[WoShouListCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.backgroundColor = Color_backgroundColor;
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        self.bgView = [UIView new];
        self.bgView.backgroundColor = HexColor(0xffffff);
        self.bgView.layer.masksToBounds = YES;
        self.bgView.layer.cornerRadius = 6;
        [self.contentView addSubview:self.bgView];
        
        self.noTitleLab = [UILabel new];
        self.noTitleLab.textColor = HexColor(0x9C9DB3);
        self.noTitleLab.font = [UIFont systemFontOfSize:12];
        [self.bgView addSubview:self.noTitleLab];
        
        self.noLab = [UILabel new];
        self.noLab.textColor = HexColor(0x2B2C44);
        self.noLab.font = BoldFontOfSize(12);
        [self.bgView addSubview:self.noLab];
        
        self.fuZhiBtn = [UIButton new];
        [self.bgView addSubview:self.fuZhiBtn];
        
        self.fromAddLab = [UILabel new];
        self.fromAddLab.textColor = HexColor(0x2B2C44);
        self.fromAddLab.font = BoldFontOfSize(20);
        self.fromAddLab.textAlignment = NSTextAlignmentCenter;
        [self.bgView addSubview:self.fromAddLab];
        
        self.statusImgView = [UIImageView new];
        [self.bgView addSubview:self.statusImgView];
        
        self.statusLab = [UILabel new];
        self.statusLab.textColor = HexColor(0x2B2C44);
        self.statusLab.font = BoldFontOfSize(12);
        [self.bgView addSubview:self.statusLab];
        
        self.toAddLab = [UILabel new];
        self.toAddLab.textColor = HexColor(0x2B2C44);
        self.toAddLab.font = BoldFontOfSize(20);
        self.toAddLab.textAlignment = NSTextAlignmentCenter;
        [self.bgView addSubview:self.toAddLab];
        
        self.faHuoTitleLab = [UILabel new];
        self.faHuoTitleLab.textColor = HexColor(0x9C9DB3);
        self.faHuoTitleLab.font = [UIFont systemFontOfSize:12];
        [self.bgView addSubview:self.faHuoTitleLab];
        
        self.faHuoLab = [UILabel new];
        self.faHuoLab.textColor = HexColor(0x2B2C44);
        self.faHuoLab.font = [UIFont systemFontOfSize:12];
        [self.bgView addSubview:self.faHuoLab];
        
        self.companyTitleLab = [UILabel new];
        self.companyTitleLab.textColor = HexColor(0x9C9DB3);
        self.companyTitleLab.font = [UIFont systemFontOfSize:12];
        [self.bgView addSubview:self.companyTitleLab];
        
        self.companyLab = [UILabel new];
        self.companyLab.textColor = HexColor(0x2B2C44);
        self.companyLab.font = [UIFont systemFontOfSize:12];
        [self.bgView addSubview:self.companyLab];
        
        self.timeTitleLab = [UILabel new];
        self.timeTitleLab.textColor = HexColor(0x9C9DB3);
        self.timeTitleLab.font = [UIFont systemFontOfSize:12];
        [self.bgView addSubview:self.timeTitleLab];
        
        self.timeLab = [UILabel new];
        self.timeLab.textColor = HexColor(0x2B2C44);
        self.timeLab.font = [UIFont systemFontOfSize:12];
        [self.bgView addSubview:self.timeLab];
    }
    return self;
}

-(void)setModel:(WoShouYunDanModel *)model {
    _model = model;
    [self configUI];
}

- (void)configUI {
    self.bgView.frame = CGRectMake(15, 10, ScreenW - 30, 203);
    
    self.noTitleLab.text = @"运单号：";
    self.noTitleLab.nim_left = 10;
    self.noTitleLab.nim_top = 15;
    [self.noTitleLab sizeToFit];
    
    self.noLab.text = self.model.wa_num;
    self.noLab.nim_left = self.noTitleLab.nim_right;
    [self.noLab sizeToFit];
    self.noLab.nim_centerY = self.noTitleLab.nim_centerY;
    
    self.fuZhiBtn.nim_left = self.noLab.nim_right + 6;
    self.fuZhiBtn.nim_width = 18;
    self.fuZhiBtn.nim_height = 18;
    self.fuZhiBtn.nim_centerY = self.noLab.nim_centerY;
    [self.fuZhiBtn setImage:[UIImage imageNamed:@"icon_ladingbill_erweima"] forState:0];
    
    self.statusImgView.nim_width = 81;
    self.statusImgView.nim_height = 10;
    self.statusImgView.nim_left = (self.bgView.nim_width - 81) * 0.5;
    self.statusImgView.nim_top = self.fuZhiBtn.nim_bottom + 33;
    if ([self.model.status isEqualToString:@"2"]) {
        [self.statusImgView setImage:[UIImage imageNamed:@"ladingBill_sure"]];
    }else if ([self.model.status isEqualToString:@"5"]) {
        [self.statusImgView setImage:[UIImage imageNamed:@"ladingBill_chuFa"]];
    }else if ([self.model.status isEqualToString:@"6"]) {
        [self.statusImgView setImage:[UIImage imageNamed:@"ladingBill_chuFa"]];
    }else if ([self.model.status isEqualToString:@"7"]) {
        [self.statusImgView setImage:[UIImage imageNamed:@"ladingBill_chuFa"]];
    }else if ([self.model.status isEqualToString:@"8"]) {
        [self.statusImgView setImage:[UIImage imageNamed:@"ladingBill_chuFa"]];
    }else if ([self.model.status isEqualToString:@"9"]) {
        [self.statusImgView setImage:[UIImage imageNamed:@"ladingBill_daoDa"]];
    }else if ([self.model.status isEqualToString:@"11"]) {
        [self.statusImgView setImage:[UIImage imageNamed:@"ladingBill_zhuangChe"]];
    }else if ([self.model.status isEqualToString:@"12"]) {
        [self.statusImgView setImage:[UIImage imageNamed:@"ladingBill_finish"]];
    }else if ([self.model.status isEqualToString:@"13"]) {
        [self.statusImgView setImage:[UIImage imageNamed:@"ladingBill_zuoFei"]];
    }
    
    self.statusLab.text = self.model.status_name;
    [self.statusLab sizeToFit];
    self.statusLab.nim_centerX = self.statusImgView.nim_centerX;
    self.statusLab.nim_top = self.statusImgView.nim_bottom + 10;
    
    self.fromAddLab.nim_left = 10;
    self.fromAddLab.text = self.model.origin;
    [self.fromAddLab sizeToFit];
    self.fromAddLab.nim_width = self.statusImgView.nim_left - 20;
    self.fromAddLab.nim_centerY = self.statusImgView.nim_centerY;
    
    self.toAddLab.nim_left = 10+self.statusImgView.nim_right;
    self.toAddLab.text = self.model.destination;
    [self.toAddLab sizeToFit];
    self.toAddLab.nim_width = self.statusImgView.nim_left - 20;
    self.toAddLab.nim_centerY = self.statusImgView.nim_centerY;
    
    self.timeTitleLab.text = @"要求到达时间：";
    [self.timeTitleLab sizeToFit];
    self.timeTitleLab.nim_left = 10;
    self.timeTitleLab.nim_top = self.bgView.nim_height - 15 - self.timeTitleLab.nim_height;
    
    self.timeLab.text = self.model.demandTime;
    [self.timeLab sizeToFit];
    self.timeLab.nim_left = self.timeTitleLab.nim_right;
    self.timeLab.nim_centerY = self.timeTitleLab.nim_centerY;
    self.timeLab.nim_width = self.bgView.nim_width - 10 - self.timeTitleLab.nim_right;
    
    self.companyTitleLab.text = @"承运方：";
    [self.companyTitleLab sizeToFit];
    self.companyTitleLab.nim_left = self.timeTitleLab.nim_left;
    self.companyTitleLab.nim_top = self.timeTitleLab.nim_top - 5 - self.companyTitleLab.nim_height;
    
    self.companyLab.text = self.model.pl_name;
    [self.companyLab sizeToFit];
    self.companyLab.nim_left = self.companyTitleLab.nim_right;
    self.companyLab.nim_centerY = self.companyTitleLab.nim_centerY;
    self.companyLab.nim_width = self.bgView.nim_width - 10 - self.companyTitleLab.nim_right;
    
    self.faHuoTitleLab.text = @"发货方：";
    [self.faHuoTitleLab sizeToFit];
    self.faHuoTitleLab.nim_left = self.timeTitleLab.nim_left;
    self.faHuoTitleLab.nim_top = self.companyTitleLab.nim_top - 5 - self.faHuoTitleLab.nim_height;
    
    self.faHuoLab.text = self.model.send_name;
    [self.faHuoLab sizeToFit];
    self.faHuoLab.nim_left = self.faHuoTitleLab.nim_right;
    self.faHuoLab.nim_centerY = self.faHuoTitleLab.nim_centerY;
    self.faHuoLab.nim_width = self.bgView.nim_width - 10 - self.faHuoTitleLab.nim_right;
    
    self.height = self.bgView.nim_bottom;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
